﻿using System;
using System.Configuration;

namespace File_SyncUI.Properties {
    
    
    // 通过此类可以处理设置类的特定事件:
    //  在更改某个设置的值之前将引发 SettingChanging 事件。
    //  在更改某个设置的值之后将引发 PropertyChanged 事件。
    //  在加载设置值之后将引发 SettingsLoaded 事件。
    //  在保存设置值之前将引发 SettingsSaving 事件。
    internal sealed partial class Settings {
        
        public Settings() {
            // // 若要为保存和更改设置添加事件处理程序，请取消注释下列行:
            //
            // this.SettingChanging += this.SettingChangingEventHandler;
            //
            // this.SettingsSaving += this.SettingsSavingEventHandler;
            //
        }
        
        private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) {
            // 在此处添加用于处理 SettingChangingEvent 事件的代码。
        }
        
        private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) {
            // 在此处添加用于处理 SettingsSaving 事件的代码。
        }
    }

	public class SyncPair : ConfigurationElement
	{
		public SyncPair()
		{
			
		}

		public SyncPair(string _Name)
		{
			Name = _Name;
		}

		[ConfigurationProperty("Name", IsKey = true)]
		[StringValidator(MaxLength = 30, InvalidCharacters = " <>&\'\"")]
		public String Name
		{
			get
			{ return (String)this["Name"]; }
			set
			{ this["Name"] = value; }
		}

		[ConfigurationProperty("ExcludePath")]
		[StringValidator(InvalidCharacters = " <>&\'\"")]
		public String ExcludePath
		{
			get
			{ return (String)this["ExcludePath"]; }
			set
			{ this["ExcludePath"] = value; }
		}

		[ConfigurationProperty("ExcludeType")]
		[StringValidator(InvalidCharacters = " <>&\'\"")]
		public String ExcludeType
		{
			get
			{ return (String)this["ExcludeType"]; }
			set
			{ this["ExcludeType"] = value; }
		}

		[ConfigurationProperty("SourceDir")]
		[StringValidator(MaxLength = 260, InvalidCharacters = " <>&\'\"")]
		public String SourceDir
		{
			get
			{ return (String)this["SourceDir"]; }
			set
			{ this["SourceDir"] = value; }
		}

		[ConfigurationProperty("TargetDir")]
		[StringValidator(MaxLength = 260, InvalidCharacters = " <>&\'\"")]
		public String TargetDir
		{
			get
			{ return (String)this["TargetDir"]; }
			set
			{ this["TargetDir"] = value; }
		}

		[ConfigurationProperty("CheckMD5")]
		[IntegerValidator(MinValue = 0, MaxValue = 2)]
		public int CheckMD5
		{
			get
			{ return (int)this["CheckMD5"]; }
			set
			{ this["CheckMD5"] = value; }
		}

		[ConfigurationProperty("SafeCopy")]
		[IntegerValidator(MinValue = 0, MaxValue = 2)]
		public int SafeCopy
		{
			get
			{ return (int)this["SafeCopy"]; }
			set
			{ this["SafeCopy"] = value; }
		}

		[ConfigurationProperty("Monitor")]
		[IntegerValidator(MinValue = 0, MaxValue = 1)]
		public int Monitor
		{
			get
			{ return (int)this["Monitor"]; }
			set
			{ this["Monitor"] = value; }
		}

		[ConfigurationProperty("Remark", IsKey = true)]
		[StringValidator(MaxLength = 50, InvalidCharacters = " <>&\'\"")]
		public String Remark
		{
			get
			{ return (String)this["Remark"]; }
			set
			{ this["Remark"] = value; }
		}
	}

	[ConfigurationCollection(typeof(SyncPair))] 
	internal sealed class SyncPairs : ConfigurationElementCollection
	{
		protected override ConfigurationElement CreateNewElement()
		{
			return new SyncPair();
		}
		protected override object GetElementKey(ConfigurationElement element)
		{
			return ((SyncPair)element).Name;
		}

		public override ConfigurationElementCollectionType CollectionType
		{
			get
			{
				return ConfigurationElementCollectionType.BasicMap;
			}
		}

		protected override string ElementName
		{
			get
			{
				return "SyncPair";
			}
		}

		public SyncPair this[int index]
		{
			get
			{
				return (SyncPair)BaseGet(index);
			}
			set
			{
				if (BaseGet(index) != null)
				{
					BaseRemoveAt(index);
				}
				BaseAdd(index, value);
			}
		}

		public int IndexOf(SyncPair value)
		{
			return BaseIndexOf(value);
		}

		public void Add(SyncPair value)
		{
			BaseAdd(value);

			// Add custom code here.
		}

		protected override void
			BaseAdd(ConfigurationElement element)
		{
			BaseAdd(element, false);
			// Add custom code here.
		}

		public void Remove(SyncPair value)
		{
			if (BaseIndexOf(value) >= 0)
				BaseRemove(value.Name);
		}

		public void RemoveAt(int index)
		{
			BaseRemoveAt(index);
		}

		public void Remove(string name)
		{
			BaseRemove(name);
		}

		public void Clear()
		{
			BaseClear();
			// Add custom code here.
		}
	}

	internal sealed class CustomPropSectionParser : ConfigurationSection
	{
		[ConfigurationProperty("", IsDefaultCollection = true)]
		public SyncPairs Pairs
		{
			get
			{ return (SyncPairs)this[""]; }
		}
	}
}
